//
// Created by jiangpenghui on 2023/4/20.
//

#include "fill_array.h"

int fill_array(double *ar, int limit) {
    using namespace std;
    double temp;
    int i;
    for (i = 0; i < limit; ++i) {
        cout << "Enter value #" << (i + 1) << "：";
        cin >> temp;
        if (!cin) {
            cin.clear();
            while (cin.get() != '\n')continue;

            cout << "Bad input " << endl;
            break;
        } else if (temp < 0)
            break;
        ar[i] = temp;
    }
    return i;
}
